package team.seekers.oj.homework.conventer;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.assertj.core.util.Lists;
import team.seekers.oj.common.converter.BaseConvertUtils;
import team.seekers.oj.homework.dto.HomeworkProblemListDTO;

import java.io.*;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @Description DTO-DO 特殊转换方法的统一收口处
 * @author hbc
**/
public class HomeworkConvertUtils extends BaseConvertUtils {


    public static List<HomeworkProblemListDTO> problemsTo(byte[] problems) throws IOException, ClassNotFoundException {
        //将取出的二进制数据反序列化成序列化的对象，依旧使用对象流处理
        if(problems == null){
            return new ArrayList<HomeworkProblemListDTO>();
        }
        ByteArrayInputStream byteInt=new ByteArrayInputStream(problems);
        ObjectInputStream objInt=new ObjectInputStream(byteInt);
        List<HomeworkProblemListDTO> o=(List<HomeworkProblemListDTO>)objInt.readObject();
        return o;
    }

    public static byte[] problemsFrom(List<HomeworkProblemListDTO> contestProblemListDTOList) throws IOException {
        ByteArrayOutputStream byt=new ByteArrayOutputStream();
        ObjectOutputStream obj=new ObjectOutputStream(byt);
        obj.writeObject(contestProblemListDTOList);
        return byt.toByteArray();
    }

}